package com.chenjun.common.ctrlformat;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.springframework.format.AnnotationFormatterFactory;
import org.springframework.format.Parser;
import org.springframework.format.Printer;

import com.chenjun.common.ctrlformat.annotation.ListFormat;

/**
 * @Title ListFormatAnnotationFormatterFactory
 * @Description:
 * @author 李伟
 * @date 2015年7月31日 上午11:24:47
 */
public class ListFormatAnnotationFormatterFactory implements AnnotationFormatterFactory<ListFormat> {
	private static final Set<Class<?>> fieldTypes;
	//private static final ListFormatter formatter;

	static {
		System.out.println("factory");
		Set<Class<?>> set = new HashSet<Class<?>>();
		set.add(List.class);
		fieldTypes = set;
		//formatter = new ListFormatter(); 
	}

	/* 
	 * @see org.springframework.format.AnnotationFormatterFactory#getFieldTypes()
	 */
	@Override
	public Set<Class<?>> getFieldTypes() {
		return fieldTypes;
	}

	/* 
	 * @see org.springframework.format.AnnotationFormatterFactory#getPrinter(java.lang.annotation.Annotation, java.lang.Class)
	 */
	@Override
	public Printer<?> getPrinter(ListFormat annotation, Class<?> fieldType) {
		return new ListFormatter(annotation.value());
	}

	/* 
	 * @see org.springframework.format.AnnotationFormatterFactory#getParser(java.lang.annotation.Annotation, java.lang.Class)
	 */
	@Override
	public Parser<?> getParser(ListFormat annotation, Class<?> fieldType) {
		return new ListFormatter(annotation.value());
	}

}
